package com.cheboohui.iqs.deal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.config.Config;
import com.cheboohui.iqs.config.PrivateTool;
import com.cheboohui.iqs.controller.BaseController;

public class BackDeal {
	/**
	 * logger:日志工具.
	 */
	private static Log log = LogFactory.getLog(BackDeal.class);
	/**
	 * 回调处理方法
	 * 
	 * @param request
	 * @param response
	 * @param type
	 *            0统一回调;1支付回调;2承保回调;3配送回调
	 */
	public static void back(HttpServletRequest request, HttpServletResponse response, int type) {
		log.info("进入" + Config.value + ",回调处理接口....");
		try {
			JSONObject param = PrivateTool.paramtenToJson(request.getParameterMap());
			if (null == param){
				BaseController.setResponseText(response, "请求参数获取转化异常");
				return;
			}
			log.info(Config.value + ",回调处理接口请求参数:" + param);
			BaseController.setResponseText(response, back(param, type));
		} catch (Exception e) {
			log.error(Config.value + ",回调处理接口实现异常:" + e);
			BaseController.setResponseText(response, "回调处理接口实现异常:" + e.getMessage());
		}
	}

	/**
	 * 回调接口处理
	 * 
	 * @param param
	 * @param type
	 * @return
	 */
	public static String back(JSONObject param, int type) {
		if (0 == type) {
			log.info("统一回调接口....");
			return "通知后台处理该接口";
		} else if (1 == type) {
			log.info("支付回调接口....");
			return "通知后台处理该接口";
		} else if (2 == type) {
			log.info("承保回调接口...");
			return "通知后台处理该接口";
		} else if (3 == type) {
			log.info("配送回调接口...");
			return "通知后台处理该接口";
		} else {
			log.info("其他回调接口请求.........");
			return "通知后台处理该接口";
		}
	}
}
